﻿using System;
using System.Linq;
using SportTraining.Core.Dal;
using SportTraining.Core.Domain;

namespace SportTraining.Core.Linq2Sql.Dal
{
    public class PriceDal : BaseDal,IPriceDal
    {
        public PriceDal(IDataContext dataContext) : base(dataContext)
        {
        }

        #region Implementation of IBaseDal<IPrice>

        public IPrice GetById(int id)
        {
            return dataContext.Prices.FirstOrDefault(item => item.Id == id);
        }

        public void Add(IPrice entity)
        {
            if (!(entity is Price))
            {
                throw new ArgumentException("Bad Price class");
            }

            dataContext.Prices.InsertOnSubmit((Price)entity);
        }

        public void Delete(IPrice entity)
        {
            if (!(entity is Price))
            {
                throw new ArgumentException("Bad Price class");
            }

            dataContext.Prices.DeleteOnSubmit((Price)entity);
        }

        public IQueryable<IPrice> SelectAll()
        {
            return dataContext.Prices;
        }
        #endregion
    }
}